<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>attach event</title>
  <script>
    function addEvent (obj, ev, fn) {
      if (obj.attachEvent) {
        // detachEvent
        obj.attachEvent('on' + ev, fn)
      } else {
        // removeLi
        obj.addEventListener(ev, fn, false)
      }
    }
    window.onload = function () {
      var obt = document.getElementById('btn')

      if (obt.attachEvent) {
        obt.attachEvent('onclick', function () {
          console.log(1)
        })
      } else if (obt.addEventListener) {
        obt.addEventListener('click', function () {
          console.log(2)
        }, false)
        // obt.removeEventListener
      } else {
        console.log('111')
      }
    }
  </script>
</head>
<body>
  <input type="button" value="按钮" id="btn" />
</body>
</html>